l107/H16 Ajax/auteurs.php

<?php ?> <!DOCTYPE html> <html lang="en"> <head> <script src="../ajax.js"></script> <link href="css/ajax.css" rel="stylesheet" type="text/css"> <title>Auteurs met ajax</title> <script> window.onload = setEvents function setEvents(){ document.getElementById('auteurnr').onchange = auteurChange } function auteurChange(){ var auteurnr =this.options[this.selectedIndex].value; //document.location='?auteurnr=' + auteurnr; ajax('auteurdetails.php?auteurnr='+ auteurnr ,'auteurdetails') } </script> </head> <body> <?php include('../db.php');//verbinding database echo "<div><span class='veldnaam'>Auteur:</span>"; ?> <select name='auteurnr' id='auteurnr'> <option value=''></option> <?php //alle auteurs ophalen $query ="select * from auteurs order by achternaam"; $result = mysqli_query($db, $query) or die(mysqli_error($db).": $query"); while($row = mysqli_fetch_array($result)){ //$selected = $auteurnr == $row['auteurnr']?"selected":""; echo "<option $selected value='$row[auteurnr]'>$row[voornaam] $row[tussenvoegsel] $row[achternaam]</option>\n"; } echo "</select></div>"; echo "<div id='auteurdetails'></div>"; ?> <hr> <p><input type="checkbox" id='alertRespons'>Alert antwoord</p> <div id='ajaxtext'></div> </body> </html>

Resultaat

Made by Thijs Aarnoudse